import { Component, Vue, Inject } from 'vue-property-decorator';

import { IStudentScore } from '@/shared/model/student-score.model';
import StudentScoreService from './student-score.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class StudentScoreDetails extends Vue {
  @Inject('studentScoreService') private studentScoreService: () => StudentScoreService;
  @Inject('alertService') private alertService: () => AlertService;

  public studentScore: IStudentScore = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.studentScoreId) {
        vm.retrieveStudentScore(to.params.studentScoreId);
      }
    });
  }

  public retrieveStudentScore(studentScoreId) {
    this.studentScoreService()
      .find(studentScoreId)
      .then(res => {
        this.studentScore = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
